/*
 * 获取列表数据
 * @Author: Chenliang(930225)
 * @Date: 2019-10-12 15:59:28
 * @LastEditors: Chenliang(930225)
 * @LastEditTime: 2019-10-15 10:29:29
 */

import * as statisticsService from '../service/statistics';

export default {
  namespace: 'statistics',
  state: {
    statistics: null, 
  },
  reducers: {
    /**
     * @description: 更新数据
     * @param {type} 
     */    
    updateStatistics(state, {
      payload: statistics
    }) {
      return {
        ...state,
        ...statistics
      }
    },
  },
  effects: {
    /**
     * @description: 获取信息
     * @param {type} 
     */    
    * getStatistics({ payload }, { call, put }) {
      const { year } = payload
      const resp = yield call(statisticsService.statistics, { year });
      if (resp.data && !resp.data.error_code && !resp.data.status_code) {
        //   更新数据到state
        return yield put({
          type: 'updateStatistics',
          payload: {
            statistics: resp.data.array
          }
        })
      }
      return resp;
    }
  }
}
